package com.tucue.controller;

import com.tucue.dao.ActivityMapper;
import com.tucue.model.Activity;
import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.validation.Valid;
import java.util.List;

@Controller
@RequestMapping("/add")
public class TestController {
	@RequestMapping("/open")
	public String printWelcome() {
		return "appAddActivity";
	}

//	@RequestMapping(value="/activity", method = RequestMethod.POST)
//	public String addActivity(@ModelAttribute @Valid Activity act, BindingResult result) {
//		if(result.hasErrors()) {
//			List<FieldError> errors = result.getFieldErrors();
//			for(FieldError err : errors) {
//				System.out.println("ObjectName:" + err.getObjectName() + "\tFieldName:" + err.getField()
//						+ "\tFieldValue:" + err.getRejectedValue() + "\tMessage:" + err.getDefaultMessage());
//			}
//			return "error";
//		}
//		try{
//			SqlSession mysession =SqlSessionUtil.getSqlSession();
//			ActivityMapper activityMapper=mysession.getMapper(ActivityMapper.class);
//			activityMapper.insert(act);
//
//			mysession.commit();
//			mysession.close();
//		} catch (Exception ex) {
//			ex.printStackTrace();
//			return "error";
//		}
//		return "Success";
//	}




}